/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
// pcombo.hpp - PegComboBox class definition.
//
// Author: Kenneth G. Maxwell
//
// Copyright (c) 1997-2000 Swell Software 
//              All Rights Reserved.
//
// Unauthorized redistribution of this source code, in whole or part,
// without the express written permission of Swell Software
// is strictly prohibited.
//
// Notes:
//
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/

#ifndef _PEGCOMBO_
#define _PEGCOMBO_

class PegComboBox;        // forward reference

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
class ComboList : public PegVertList
{
    public:
        ComboList(PegThing *pBox, PegRect &Size, PEGUSHORT Id,
                  PEGULONG Style);

        virtual PEGINT Message(const PegMessage &Mesg);
        virtual void PositionChildren(void) {PegVertList::PositionChildren();}
        virtual void CloseList();

    private:
        PegThing *mpBox;

};

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
class PegComboBox : public PegThing
{
    public:
        PegComboBox(const PegRect &Rect, PEGUSHORT Id = 0, 
                    PEGULONG Style = FF_THIN);
        virtual ~PegComboBox();

        virtual void Add(PegThing *pChild, PEGBOOL Show = TRUE);
        virtual void AddToEnd(PegThing *pChild, PEGBOOL Show = TRUE);
        virtual PEGINT Clear() {return mpList->Clear();}
        void CloseList(void);
        virtual void Draw(const PegRect &Invalid);

        virtual PegThing *Find(PEGUSHORT Id, PEGBOOL Recursive = TRUE);
        virtual PEGINT GetIndex(PegThing *Who) {return mpList->GetIndex(Who);}
        PEGINT GetCloseHeight(void) {return mCloseHeight;}
        ComboList *GetListPointer() {return mpList;}
        PEGINT GetNumItems(void) {return mpList->GetNumItems();}
        PEGINT GetOpenHeight(void) {return mOpenHeight;}
        virtual PegThing *GetSelected(void) {return mpList->GetSelected();}

        virtual PEGINT GetSelectedIndex(void) 
        {
            return mpList->GetSelectedIndex();
        }
        virtual PegThing *GetThing(PEGINT Index) 
        {
            return mpList->GetThing(Index);
        }

        virtual void Insert(PegThing *What, PEGINT Where, 
                            PEGBOOL Select = TRUE, PEGBOOL Show = TRUE);
        PEGBOOL IsOpen(void) {return mOpen;}

        virtual PEGINT Message(const PegMessage &Mesg);

        void OpenList(void);

        PegThing *PageDown(void) {return mpList->PageDown();}
        PegThing *PageUp(void) {return mpList->PageUp();}

        virtual PegThing *Remove(PegThing *pChild);
        virtual void Resize(const PegRect &NewSize);
        PegThing *SelectNext(void) {return mpList->SelectNext();}
        PegThing *SelectPrevious(void) {return mpList->SelectPrevious();}
        void SetOpenHeight(PEGINT Height) {mOpenHeight = Height;}
        void SetScrollMode(PEGUINT Mode);

        virtual void SetSelected(PegThing *Who)
        {
            mpList->SetSelected(Who);
            CaptureSelectedToBitmap();
        }
        virtual PegThing *SetSelected(PEGINT Index)
        {
            PegThing *pReturn = mpList->SetSelected(Index);
            CaptureSelectedToBitmap();
            return pReturn;
        }

        void SetSeparation(PEGINT Sep) {mpList->SetSeparation(Sep);}

        enum ButtonIds {
            IDB_OPEN = 1000
        };

    protected:
        void CalcCloseHeight(void);
        void CaptureSelectedToBitmap(void);
        void SendListSelect(void);

        PegIconButton *mpOpenButton;
        ComboList *mpList;
        PegBitmap *mpBitmap;
        PegThing *mpOldSelThing;

        PEGINT mOpenHeight;
        PEGINT mCloseHeight;

        PEGBOOL mOpen;

};


/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
class PegTextComboBox : public PegTextButton
{
    public:
        PegTextComboBox(const PegRect &Rect, PEGUSHORT Id = 0, 
                    PEGULONG Style = AF_ENABLED);
        virtual ~PegTextComboBox();

        virtual void AddItem(PEGUINT StringId, PEGUSHORT Id = 0);
        virtual void AddItem(const PEGCHAR *pText, PEGUSHORT Id = 0);
        virtual void AddItemToEnd(PEGUINT StringId, PEGUSHORT Id = 0);
        virtual void AddItemToEnd(const PEGCHAR *pText, PEGUSHORT Id = 0);
        virtual PEGINT Clear() {return mpList->Clear();}
        void CloseList(void);
        virtual void DisableItem(PEGINT Index);
        virtual void Draw(const PegRect &Invalid);
        virtual void EnableItem(PEGINT Index);

        virtual PegThing *Find(PEGUSHORT Id, PEGBOOL Recursive = TRUE);
        virtual PEGINT GetIndex(PegThing *Who) {return mpList->GetIndex(Who);}
        ComboList *GetListPointer() {return mpList;}
        PEGINT GetNumItems(void) {return mpList->GetNumItems();}
        PEGINT GetOpenHeight(void) {return mOpenHeight;}
        virtual PegThing *GetSelected(void) {return mpList->GetSelected();}

        virtual PEGINT GetSelectedIndex(void) 
        {
            return mpList->GetSelectedIndex();
        }
        virtual PegThing *GetThing(PEGINT Index) 
        {
            return mpList->GetThing(Index);
        }

        virtual void InsertItem(PEGUINT StringId, PEGINT Where, 
                            PEGBOOL Select = TRUE, PEGUSHORT Id = 0);
        virtual void InsertItem(const PEGCHAR *pText, PEGINT Where, 
                            PEGBOOL Select = TRUE, PEGUSHORT Id = 0);
        PEGBOOL IsOpen(void) {return mOpen;}

        virtual PEGINT Message(const PegMessage &Mesg);

        void OpenList(void);

        PegThing *PageDown(void) {return mpList->PageDown();}
        PegThing *PageUp(void) {return mpList->PageUp();}

        virtual void RemoveItem(PEGINT Index);

        virtual void Select(PegThing *Who)
        {
            mpList->SetSelected(Who);
            CaptureSelected();
        }
        virtual PegThing *Select(PEGINT Index)
        {
            PegThing *pReturn = mpList->SetSelected(Index);
            CaptureSelected();
            return pReturn;
        }

        PegThing *SelectNext(void) {return mpList->SelectNext();}
        PegThing *SelectPrevious(void) {return mpList->SelectPrevious();}
        void SetOpenHeight(PEGINT Height) {mOpenHeight = Height;}
        void SetScrollMode(PEGUINT Mode);
        void SetSeparation(PEGINT Sep) {mpList->SetSeparation(Sep);}

        void SetTextColor(PEGUBYTE Index, PEGUINT ColorId);
        void SetTextFont(PEGUINT FontId);

    protected:
        void CaptureSelected(void);
        void SendListSelect(void);
        virtual PegThing *ConstructItem(PEGUINT StringId, PEGUSHORT Id);
        virtual PegThing *ConstructItem(const PEGCHAR *pText, PEGUSHORT Id);

        PEGUINT mTextColorIds[4];

        ComboList *mpList;
        PegThing *mpOldSelThing;

        PEGUINT mTextFontId;
        PEGINT mOpenHeight;
        PEGBOOL mOpen;

};






#endif


